﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MDIDemo.Windows.Report
{
    public partial class frmBaoCaoDoanhSoTheoLoaiHang : DevExpress.XtraEditors.XtraForm
    {
        Dictionary<string, object> _valueList = new Dictionary<string, object>();

        public Dictionary<string, object> ValueList
        {
            get { return _valueList; }
            set { _valueList = value; }
        }
        DataSet _ds = null;
        public DataSet DataSource { get { return _ds; } }
        public string Type
        {
            get
            {
                return rType.EditValue.ToString();
            }

        }

        public frmBaoCaoDoanhSoTheoLoaiHang()
        {
            InitializeComponent();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            Close();
        }
        public DataSet BuildDataSourceNXHD()
        {
            string query = "";
            if (rType.EditValue.ToString() == "BPTDSBH")
                query = @"exec procNXHANG_getByMaHang @NGAYCT='{0:yyyy-MM-dd}', @LOAICT='{1}'";
            else query = @"exec procNXHANG_getByMaHangMonth @Month={0:MM}, @year={0:yyyy}, @LOAICT='{1}'";

            query = string.Format(query, txtDate.EditValue,"BH001");
            BUS.CommonControl ctr = new BUS.CommonControl();
            _ds = ctr.executeSelectQueries(query);
            return _ds;
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            _ds = BuildDataSourceNXHD();

            if (_ds.Tables.Count == 0)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            bool isdata = false;
            foreach (DataTable dt in _ds.Tables)
            {
                if (dt.Rows.Count > 0)
                {
                    isdata = true;
                    break;
                }
            }
            if (isdata == false)
            {
                XtraMessageBox.Show("Dữ liệu không tồn tại!");
                return;
            }
            _valueList.Add("Date", txtDate.EditValue);
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }


        private void frmBangKeGTGT_Load(object sender, EventArgs e)
        {
            txtDate.EditValue = frmMain.__ngayMoSo;
        }
    }
}